package com.personal.gateway.flinkAllCommand.configurationOption.configurationType;

import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;

import java.util.ArrayList;
import java.util.List;

/**
 * @author BigHead
 * @date 2022/1/10 16:30
 * @description ConfigurationTypeEnum
 */
public class ConfigurationTypeEnum extends AbstractConfigurationType<Enum<? extends ConfigurationTypeEnumInterface>> {
    public ConfigurationTypeEnum(Class<Enum<? extends ConfigurationTypeEnumInterface>> configurationType) {
        super(configurationType);
        this.setExampleValue();
    }

    @Override
    public String getTypeString() {
        return "下拉枚举类型";
    }

    @Override
    public void setValue(Enum<? extends ConfigurationTypeEnumInterface> value) {
        this.value = value;
    }

    @SafeVarargs
    @Override
    public final void setExampleValue(Enum<? extends ConfigurationTypeEnumInterface>... exampleValue) {
        this.exampleValue = configurationType.getEnumConstants();
    }

    @Override
    public Enum<? extends ConfigurationTypeEnumInterface>[] getExampleValue(ConfigurationOption<?, ?> configurationOption) {
        List<Enum<? extends ConfigurationTypeEnumInterface>> tempList = new ArrayList<>();
        for (Enum<? extends ConfigurationTypeEnumInterface> configurationTypeEnumInterface: configurationType.getEnumConstants()){
            if (((ConfigurationTypeEnumInterface)configurationTypeEnumInterface).checkExampleValue(configurationOption)){
                tempList.add(configurationTypeEnumInterface);
            }
        }
        return tempList.toArray(new Enum[0]);
    }
}
